<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort() + path + "/";
    String userid = request.getParameter("userid");System.out.println(userid);
    String nowuserid = request.getParameter("nowuserid");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>证书管理列表</title>
<base target="_self" />
<%@ include file="../jslib/jquerylib.jsp" %>
<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
<link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
<link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript">
         var api = frameElement.api;
         if (api!=undefined)
         {
         	var W = api.opener;
         }
</script>
<c:if test="${requestScope.message != null}">
  <script type="text/javascript">
  		 alert("<c:out value='${requestScope.message}'></c:out>");
  		 
 </script>
</c:if>
<script type="text/javascript">
<%--    var userid;--%>
<%--	function init()--%>
<%--	{--%>
<%--		userid = eval("(" + api.data + ")").userId;--%>
<%--	}--%>
	$(document).ready( function() {
		    var common_width = window.screen.width-0;
            var common_height = window.screen.height-505;
			$("#gridTable").jqGrid({
				url:'<%=request.getContextPath() %>/system/cerifyInfo.action?userid=<%=request.getParameter("userid")%>',
				datatype: "json",
				height: 210,
				width:760,
				colNames:['id','证书编号','证书名称','证书获取人','证书获取时间','证书过期时间','证书类型','证书有效期','证书说明'],
				colModel:[
						{name:'ID',index:'ID', width:60, key:true, sorttype:"int",hidden:true,hidedlg:true}, 
						{name:'CERIFY_NO',index:'CERIFY_NO', width:120},								
						{name:'CERIFY_NAME',index:'CERIFY_NAME', width:120},								
						{name:'USERNAME',index:'USERNAME', width:70},								
						{name:'CERIFY_DATE',index:'CERIFY_DATE', width:110},
						{name:'CERIFY_PAST_TIME',index:'CERIFY_PAST_TIME', width:110,
					 formatter:'date',editrules:{date:true},search:false,editable:false,
				     formatoptions: {srcformat:'Y-m-d',newformat:'Y-m-d'},datefmt:'Y-m-d H:i:s'},
						{name:'CERIFY_TYPE',index:'CERIFY_TYPE', width:70},
						{name:'CERIFY_OVERDATE',index:'CERIFY_OVERDATE', width:70},
						{name:'CERIFY_DESC',index:'CERIFY_DESC', width:100}
			],
			shrinkToFit:false,
			sortname:'ID',
			sortorder:'desc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			//gridview: true,  //提升速度
			rownumbers: true,//显示行号0
			rownumWidth: 30, //行号的宽度
			rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
			rowList:[10,20,50,200,500],
			toolbar: [false,"top"],
            jsonReader: {
                root:"rows",        // 数据行（默认为：rows）
                page: "page",   // 当前页
                total: "total",  // 总页数
                records: "records",  // 总记录数
                repeatitems : false     // 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
            },
            prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
            pager:"#gridPager",
			caption: "证书管理列表"									
	    });
		 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
		 
		 
  		 
		});	
		 //查看
		function download(){
			var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
				if(ids){
					var parentIds = ids.split(",");
					if(parentIds.length>1){
						alert("请一个一个下载！");
						return;
					}
					var result = window.location.href="download.action?id="+ids;
					if(result == 'success'){
						alert("保存成功!");
						location.reload();
					}
				}else{
					alert("请选择记录");
				}
		    }
			//刷新
			function refreshIt(){
				jQuery("#gridTable").jqGrid('setGridParam',
					{//?userid='+eval("(" + api.data + ")").userId
						url:'cerifyInfo!cerifyInfoExec.action?userid='+<%=request.getParameter("userid")%>
					}).trigger("reloadGrid", [{page:1}]); 
			}
			
			
			function addCerity(){
				$.dialog({
			        id:'addcerify',
			        //data:"{'userId':"+userid+"}",
			        title:'证书上传', 
			        content:'url:<%=request.getContextPath() %>/system/cerity_add.jsp?userId='+<%=request.getParameter("userid")%>,
			        okVal:false,//确定按钮文字
		            cancelVal:false,//取消按钮文字
			        min:true, //是否显示最小化按钮
			        max:false,//是否显示最大化按钮
			        fixed:false,//开启静止定位
			        lock:true,//开启锁屏
			        focus:true,//弹出窗口后是否自动获取焦点（4.2.0新增）
			        time:null,//设置对话框显示时间
			        resize:true,//是否允许用户调节尺寸
			        drag:true,//是否允许用户拖动位置
			        cache:false,//是否缓存iframe方式加载的窗口内容页	
			        width: '520px',
		        	height: 350,
		        	zIndex:3000,
		        	 close: function(){
		        		 refreshIt();
				        }
	          });
	          //refreshIt();
			    //var result = window.showModalDialog("cerity_add.jsp?userId=<%=request.getParameter("userid")%>",obj,"dialogWidth=550px;dialogHeight=360px");
				//	if(result == 'success'){
				//		refreshIt();
				//	}
			}
			function updateCerity(){
				var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
				if (!ids) {
				    alert("请先选择记录!");  
				    return false;  
				}
				if(ids.indexOf(",")!=-1){
					  alert("只能选择一条记录!");  
				        return false; 
				}
				var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
				var rid = row.ID;//获取选中行的id属性
				//var result = window.showModalDialog("checkOneCerify.action?userId=<%=request.getParameter("userid")%>&id="+rid+"",obj,"dialogWidth=550px;dialogHeight=390px");
				//	if(result == 'success'){
				//		refreshIt();
				//	}
				$.dialog({
			        id:'updatecerify',
			        title:'修改证书', 
			        content:'url:<%=request.getContextPath() %>/system/checkOneCerify.action?userId=<%=request.getParameter("userid")%>&id='+rid,
			        okVal:false,//确定按钮文字
			        cancelVal:false,//取消按钮文字
			        min:true, //是否显示最小化按钮
			        max:false,//是否显示最大化按钮
			        fixed:false,//开启静止定位
			        lock:true,//开启锁屏
			        focus:true,//弹出窗口后是否自动获取焦点（4.2.0新增）
			        time:null,//设置对话框显示时间
			        resize:true,//是否允许用户调节尺寸
			        drag:true,//是否允许用户拖动位置
			        cache:false,//是否缓存iframe方式加载的窗口内容页
			        width: '520px',
		        	height: 350,
		        	zIndex:3000,
		        	 close: function(){
		        		 refreshIt();
				        }
	          });
	          //refreshIt();
			}
			//delete
			function deleteCerity(){
				var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			    if (!ids) {
			    alert("请先选择记录!");  
			       return false;  
				} 
		       
				if(!confirm("是否确认删除 ？")){
				   return false;
				}
				 var params = {  
				        "ids": ids
				    };  
				    var actionUrl = "deleteCerity.action";  
				    $.ajax({  
				        url : actionUrl,  
				        type : "post", 
				        data : params,  
				        dataType : "json",  
				        cache : false,  
				        error : function(textStatus, errorThrown) {  
				            alert("系统ajax交互错误: " + textStatus.value);  
				        },  
				        success : function(data, textStatus) {  
				        	if(data.ajaxResult=='success'){
				        		alert("删除成功！");       
				        		refreshIt();    
				        	}else{
				        		alert("删除失败！");     
				        	   }
					     }  
			    });
			}
			
</script>
</head>
<body  >
<form action="" method="post">
  <table style="width: 100%;"   class="tableCont">
    <tr>
	      <td>
	        <input id="add" type='button' value='添加' onclick="addCerity();" class='button_b' style="width:80px;"/>
	        <input id="update" type='button' value='修改' onclick='updateCerity();' class='button_b' style="width:80px;"/>
	        <input id="search" type='button' value='查看' onclick='download()' class='button_b' style="width:80px;"/>
	        <input id="delete" type='button' value='删 除' onclick='deleteCerity();' class='button_b' style="width:80px;"/>
	        <input id="refresh" type='button' value='刷新' onclick='refreshIt()' class='button_b' style="width:80px;"/>
	      </td>
    </tr>
    <tr>
	      <td colspan="4">
	      		<table id="gridTable"></table>
	        	<div id="gridPager"></div>
	      </td>
    </tr>
  </table>
</form>
</body>
</html>
